package com.cxy.view.controller;

import com.cxy.view.bean.Result;
import com.cxy.view.service.BoxOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

// 移除嵌套，创建独立的BoxOfficeController类
@RestController
@RequestMapping("/api/boxoffice") // 直接映射到/api/boxoffice路径
public class BoxOfficeController {
    private final BoxOfficeService boxOfficeService;
//    private final BoxOfficeService boxOfficeService2;
    @Autowired // 添加依赖注入注解
    public BoxOfficeController(BoxOfficeService boxOfficeService) {
        this.boxOfficeService = boxOfficeService;
    }

    @GetMapping("/statistics")
    public Result getBoxOfficeStatistics() {
        try {
            Map<String, Object> stats = boxOfficeService.getBoxOfficeStatistics();
            return Result.success(stats);
        } catch (Exception e) {
            return Result.fail(); // 使用统一错误码
        }
    }

    @GetMapping("/statistics2")
    public Result getBoxOfficeStatistics2() {
        try {
            Map<String, Object> stats = boxOfficeService.getBoxOfficeStatistics2();
            System.out.println("请求总搜票数");
            return Result.success(stats);
        } catch (Exception e) {
            return Result.fail(); // 使用统一错误码
        }
    }

}


